<template>
	<view>
		<!-- <u-skeleton rows="3" :loading="loading" :title="false"></u-skeleton>
		<u--text> -->


			<!-- 搜索框 -->
			<view class="">
				<u-search placeholder="请输入关键字"></u-search>
			</view>

			<!-- 首页分类 -->
			<view class="">
				<u-tabs :list="list2" @click="getCateInfo"></u-tabs>
			</view>

			<!-- 轮播图 -->
			<view class="">
				<u-swiper height="230" :list="list" indicator indicatorMode="line" circular></u-swiper>
			</view>

			<!--  -->
			<view>
				<u-grid :border="false" col="5">
					<u-grid-item v-for="(listItem,listIndex) in list3" :key="listItem.id">
						<u-icon :customStyle="{paddingTop:20+'rpx'}" :name="listItem.name" :size="22"></u-icon>
						<text class="grid-text">{{listItem.title}}</text>
					</u-grid-item>
				</u-grid>
			</view>

			<!-- 倒计时 -->
			<view class="setItem">
				<view class="set_l">
					<view class="set_green">
						限时秒杀
					</view>
					<view class="">
						<u-count-down :time="30 * 60 * 60 * 1000" format="HH:mm:ss" autoStart millisecond>
							<view class="time">
								<view class="time__custom">
									<text
										class="time__custom__item">{{ timeData.hours>10?timeData.hours:'0'+timeData.hours}}</text>
								</view>
								<text class="time__doc">:</text>
								<view class="time__custom">
									<text class="time__custom__item">{{ timeData.minutes }}</text>
								</view>
								<text class="time__doc">:</text>
								<view class="time__custom">
									<text class="time__custom__item">{{ timeData.seconds }}</text>
								</view>
							</view>
						</u-count-down>
					</view>
				</view>
				<view class="set_r">
					<view class="set_r_t">
						<view class="set_green">品牌上新</view>
						<view class="set_pink">9点整，抢大牌</view>
						<view class="set_bac">疯狂抢红包 &gt;</view>
					</view>
					<view class="set_r_b">
						<view class="set_green">日用好物</view>
						<view class="set_pink">愿君多采摘</view>
						<view class="set_bac">疯狂抢红包 &gt;</view>
					</view>
				</view>
			</view>



			<!-- 商品类型切换 -->
			<view>
				<u-subsection @change="changeType" :list="list4" :current="current"></u-subsection>
			</view>

			<!-- 商品信息 -->
			<view class="">
				<view class="goodsInfo" v-for="item in goodslist1" :key="item.goodsname">
					<view class="_image">
						<image :src='item.img' mode=""></image>
					</view>
					<view class="goodsName">
						<view>
							{{item.goodsname}}
						</view>
						<view>
							¥{{item.price}}
						</view>
						<view class="del">
							¥{{item.market_price}}
						</view>
						<view @click="goDetail(item.id)" class='btn'>查看详情</view>
					</view>
				</view>
			</view>
		<!-- </u--text> -->
	</view>
</template>

<script>
	// 引入封装好的接口
	import {
		getBanner,
		getHomeCate,
		getHomeGoods
	} from '@/request/app.js'
	export default {
		data() {
			return {
				loading: true,
				timeData: {},
				list: [],
				list1: [],
				list2: [{
					name: ''
				}],
				list3: [{
						id: 1,
						name: require('../../static/img/限时抢购.png'),
						title: '限时秒杀'
					},
					{
						id: 2,
						name: require('../../static/img/积分兑换.png'),
						title: '积分兑换'
					},
					{
						id: 3,
						name: require('../../static/img/小u自营.png'),
						title: '小u自营'
					},
					{
						id: 4,
						name: require('../../static/img/畅销商品.png'),
						title: '畅销商品'
					},
					{
						id: 5,
						name: require('../../static/img/品质大牌.png'),
						title: '品质大牌'
					}
				],
				list4: ['热门推荐', '上新推荐', '全部商品'],
				current: 0,
				goodslist1: [], //存放商品
			}
		},
		methods: {
			// 点击跳转分类
			getCateInfo(index) {
				console.log(index, 'index');
				uni.switchTab({
					url: '../cate/cate?cateid=' + index.index
				})
			},
			// 商品类型切换 事件
			changeType(e) {
				console.log(e, '事件源');
				this.current = e
				this.goodsALL(e)
			},
			// 调用接口的方法
			goodsALL(e) {
				getHomeGoods()
					.then(res => {
						console.log(res, "首页商品信息");
						if (res.data.code == 200) {
							this.goodslist1 = res.data.list[e].content.map(item => ({
								goodsname: item.goodsname,
								id: item.id,
								img: this.$imgUrl + item.img,
								market_price: item.market_price,
								price: item.price,
							}))
						}
					})
			},
			// 跳转详情页事件
			goDetail(id) {
				uni.navigateTo({
					url: '../goodsDetail/goodsDetail?id=' + id
				})
			}
		},
		onLoad() {
			// 延时2秒钟
			uni.$u.sleep(2000).then(() => {
					this.loading = false
				}),
				// 调用轮播图接口
				getBanner()
				.then(res => {
					console.log(res, '轮播图响应');
					if (res.data.code == 200) {
						this.list = res.data.list.map(item => this.$imgUrl + item.img)
					}
				})
			// 首页快速分类接口
			getHomeCate()
				.then(res => {
					console.log(res, '首页分类响应');
					if (res.data.code == 200) {
						this.list2 = res.data.list.map(item => ({
							name: item.catename
						}))
					}
				})
			// 首页商品信息
			this.goodsALL(0)
		}
	}
</script>

<style lang="scss">
	.goodsInfo {
		display: flex;
		box-shadow: 2px 5px 6px rgba(0, 0, 0, 0.25);
		padding: 10px;
		box-sizing: border-box;
		margin: 17px 0;

		._image image {
			width: 120px;
			height: 110px;
			margin-right: 20px;
		}

		.goodsName view {
			width: 270px;
			margin: 5px 0;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}

		.goodsName .btn {
			width: 100px;
			background-color: bisque;
			text-align: center;
		}

		.goodsName .del {
			text-decoration: line-through;
			color: #dedede;
			font-size: 15px;
		}
	}

	.setItem {
		height: 195px;
		padding: 10px 20px;
		background-color: #eee;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		margin: 10px 0;

		.set_green {
			color: green;
		}

		.set_l {
			width: 175px;
			height: 175px;
			background-image: url('../../static/img/图1.png');
			background-repeat: no-repeat;
			background-size: 175px 175px;
			padding: 10px;
			box-sizing: border-box;

			image {
				width: 175px;
				height: 175px;
			}

			// 倒计时框架
			.time {
				@include flex;
				align-items: center;
				margin-top: 5px;

				&__custom {
					margin-top: 4px;
					width: 22px;
					height: 22px;
					background-color: $u-primary;
					border-radius: 4px;
					/* #ifndef APP-NVUE */
					display: flex;
					/* #endif */
					justify-content: center;
					align-items: center;

					&__item {
						color: #fff;
						font-size: 12px;
						text-align: center;
					}
				}

				&__doc {
					color: $u-primary;
					padding: 0px 4px;
				}

				&__item {
					color: #606266;
					font-size: 15px;
					margin-right: 4px;
				}
			}
		}

		.set_r {
			height: 175px;
			font-size: 12px;

			.set_r_t {
				width: 175px;
				height: 80px;
				background-image: url('../../static/img/图2.png');
				background-repeat: no-repeat;
				background-size: 175px 80px;
				margin-bottom: 15px;
				padding: 10px;
				box-sizing: border-box;
			}

			.set_r_b {
				width: 175px;
				height: 80px;
				background-image: url('../../static/img/图3.png');
				background-repeat: no-repeat;
				background-size: 175px 80px;
				padding: 10px;
				box-sizing: border-box;
			}

			.set_pink {
				color: red;
				margin-top: 5px;
			}

			.set_bac {
				width: 80px;
				height: 30px;
				background-color: tomato;
				color: #fff;
				line-height: 30px;
				border-radius: 0 15px 15px 0;
				font-weight: bold;
			}

			.set_green {
				color: green;
			}
		}
	}
</style>
